package com.iraeta.controller;

import com.iraeta.service.basic.CangKuService;
import com.iraeta.service.basic.PlanService;
import com.iraeta.service.etl.ErpEtlService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Component
@EnableScheduling
@EnableAsync
public class GlobalTask {
    private static final Logger logger = LoggerFactory.getLogger(GlobalTask.class);
    @Autowired
    ErpEtlService erpEtlService;
    @Autowired
    CangKuService cangKuService;
    @Autowired
    PlanService planService;

    @Scheduled(cron = "0 0,30 8,13,18 * * ?")
    @Async("cstaskexecutor")
    public void processErpData() {
        logger.info("processErpData begin");
        try {
            erpEtlService.processErpCurrentStore();         //库存现存货数量同步
        }catch (Exception e){
            logger.error("库存现存货同步错误:" + e.getMessage());
        }
        logger.info("processErpData end");
    }

    @Scheduled(cron = "0 0 0/1 * * ?")
    @Async("cstaskexecutor")
    public void updateCangKu() {
        logger.info("updateCangKu begin");
        try {
            //cangKuService.updateAllCangKu();         //更新仓库数据
        }catch (Exception e){
            logger.error("仓库数据更新:" + e.getMessage());
        }
        logger.info("updateCangKu end");
    }
}
